import WorkflowDivi from '@/components/page/WorkflowDivi';
import { format } from '@/utils/datetime';
import { renderNumber } from '@/utils/common';
import { useModel } from 'umi';
export default () => {
  const { props, permTypes } = useModel('sysInfo', (ret) => ({
    props: ret.getCurExtendProps(),
    permTypes: ret.getCurPermTypes(),
  }));
  if (!permTypes) {
    return null;
  }
  const taskColumns: API.Column[] = [
    {
      title: '申请人',
      dataIndex: 'SQR',
      key: 'SQR',
      width: 120,
      sorter: true,
      dispaly: true,
      filter: true,
      export: true,
      dataType: 'string',
    },
    {
      title: '申请时间',
      key: 'SQDT',
      dataIndex: 'SQDT',
      render: (data) => format(data, 'yyyy-MM-dd'),
      width: 120,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'date',
    },
    {
      title: '交易日期',
      key: 'JYRQ',
      dataIndex: 'JYRQ',
      render: (data) => format(data, 'yyyy-MM-dd'),
      width: 110,
      sorter: true,
      dispaly: true,
      export: true,
      dataType: 'date',
    },
    {
      title: '科目编号',
      dataIndex: 'ITNO',
      key: 'ITNO',
      width: 180,
      sorter: true,
      dispaly: true,
      filter: true,
      export: true,
      dataType: 'string',
    },
    {
      title: '科目名称',
      dataIndex: 'ITNM',
      key: 'ITNM',
      width: 180,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'string',
    },
    {
      title: '客户名称',
      dataIndex: 'CUNM',
      key: 'CUNM',
      width: 220,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'string',
    },
    {
      title: '币种',
      dataIndex: 'CYNM',
      key: 'CYNM',
      width: 120,
      sorter: true,
      dispaly: true,
      filter: true,
      export: true,
      dataType: 'string',
    },
    {
      title: '中收金额（折人民币）',
      dataIndex: 'ZSJE',
      key: 'ZSJE',
      width: 220,
      sorter: true,
      dispaly: true,
      filter: true,
      export: true,
      dataType: 'string',
    },
  ];
  const importControls: API.Control[] = [
    {
      name: 'JYRQ',
      rules: [{ required: true, message: '交易日期不能为空' }],
      type: 'text',
      label: '交易日期',
      dataType: 'date',
      grid: 12 / 24,
    },
    {
      name: 'ITNO',
      rules: [{ required: true, message: '科目编号不能为空' }],
      type: 'text',
      label: '科目编号',
      dataType: 'string',
      grid: 12 / 24,
    },
    {
      name: 'ITNM',
      rules: [{ required: true, message: '科目名称不能为空' }],
      type: 'text',
      label: '科目名称',
      dataType: 'string',
      grid: 12 / 24,
    },
    {
      name: 'CYNM',
      rules: [{ required: true, message: '币种不能为空' }],
      type: 'text',
      label: '币种',
      dataType: 'string',
      grid: 12 / 24,
    },
    {
      name: 'CUNM',
      rules: [{ required: true, message: '客户名称不能为空' }],
      type: 'text',
      label: '客户名称',
      dataType: 'string',
      grid: 12 / 24,
    },
    {
      name: 'ZSJE',
      rules: [{ required: true, message: '中收金额不能为空' }],
      type: 'text',
      label: '中收金额',
      dataType: 'number',
      grid: 12 / 24,
    },
  ];
  const renderDivi = (divis: Record<string, any>[]) => {
    if (!divis || divis.length == 0) {
      return '';
    }
    let diviStr = '';
    divis.map((d) => {
      diviStr = diviStr + d.EMNM + '(' + d.EMNO + '):' + d.DSVL + ' ';
    });
    return diviStr;
  };
  const searchColumns: API.Column[] = [
    {
      title: '客户名称',
      dataIndex: 'CUNM',
      key: 'CUNM',
      width: 220,
      sorter: true,
      dispaly: true,
      filter: true,
      ellipsis: true,
      dataType: 'string',
    },
    {
      title: '科目编号',
      dataIndex: 'ITNO',
      key: 'ITNO',
      width: 140,
      sorter: true,
      dispaly: true,
      filter: true,
      export: true,
      dataType: 'string',
    },
    {
      title: '科目名称',
      dataIndex: 'ITNM',
      key: 'ITNM',
      width: 180,
      sorter: true,
      dispaly: true,
      filter: true,
      ellipsis: true,
      dataType: 'string',
    },
    {
      title: '币种',
      dataIndex: 'CYNM',
      key: 'CYNM',
      width: 130,
      sorter: true,
      dispaly: true,
      filter: true,
      ellipsis: true,
      dataType: 'string',
    },
    {
      title: '交易日期',
      key: 'DATA_DT',
      dataIndex: 'DATA_DT',
      render: (data) => format(data, 'yyyy-MM-dd'),
      width: 140,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'date',
    },
    {
      title: '中收金额',
      dataIndex: 'ZSJE',
      key: 'ZSJE',
      render: (acbl) => renderNumber('.2f', acbl),
      width: 130,
      sorter: true,
      dispaly: true,
      filter: true,
      dataType: 'number',
    },
  ];
  if (props.isUpdate) {
    searchColumns.push({
      title: '原客户经理',
      dataIndex: 'Bgqdivi',
      key: 'Bgqdivi',
      render: (divis) => renderDivi(divis),
      width: 180,
      dispaly: true,
      ellipsis: true,
    });
  }
  const importName = props.isUpdate ? 'CompZsWorkflowUpdateApp' : 'CompZsWorkflowNewApp';
  const taskDaoName = props.isUpdate ? 'CompZsWorkflowUpdateApp' : 'CompZsWorkflowNewApp';
  const searchDaoName = props.isUpdate ? 'CompZsFlowChUpdate' : 'CompZsFlowChNew';
  const importTemplateName = props.isUpdate ? '中收关联变更申请' : '中收新户关联申请';
  const title =
    (props.isUpdate ? '中收关联变更' : '中收新户关联') +
    (props.showType === 'apply' ? '申请' : '审批');
  const options: API.OptionItem[] = [];
  const canFirstEdit = permTypes && permTypes.indexOf('D') !== -1;
  if (permTypes.indexOf('A') !== -1) {
    if (!canFirstEdit) {
      options.push({ value: '1', label: '公司类' });
      options.push({ value: '2', label: '交易银行类' });
    }
    options.push({ value: '3', label: '投行类' });
  }
  if (permTypes.indexOf('B') !== -1 && !canFirstEdit) {
    options.push({ value: '4', label: '零售类' });
  }
  if (permTypes.indexOf('C') !== -1) {
    options.push({ value: '5', label: '金融市场类' });
  }
  const searchControls: API.Control[] = [
    {
      name: 'DATA_DT',
      rules: [{ required: true, message: '客户不能为空' }],
      type: 'date',
      label: '交易日期',
      dataType: 'date',
      grid: 12 / 24,
      placeholder: '请选择日期...',
    },
    {
      name: 'TPID',
      label: '业务分类',
      rules: [{ required: true, message: '客户不能为空' }],
      options: options,
      grid: 12 / 24,
      type: 'select',
    },
  ];
  return (
    <WorkflowDivi
      taskDaoName={taskDaoName}
      taskColumns={taskColumns}
      searchDaoName={searchDaoName}
      searchColumns={searchColumns}
      importName={importName}
      importTemplateName={importTemplateName}
      importControls={importControls}
      titleColNames={['CUNM', 'DATA_DT', 'ITNM']}
      searchControls={searchControls}
      searchKeyColName="JLID"
      maxEmplCount={15}
      title={title}
      showType={props.showType}
      isUpdate={props.isUpdate}
      userIsFirstEmpl={!canFirstEdit}
      diviType="money"
    />
  );
};
